<template>
	<view>
		<u-navbar :border-bottom="false" title="设置提醒" title-color="#fff" back-icon-color="#fff">
			<template v-slot:right>
				<text v-if="time" @click="removeNoticeTime" class="nav-bar__cancel">取消提醒</text>
			</template>
		</u-navbar>
		<view class="pick-time">
			<text class="label">设置时间</text> 
			<picker mode="time" :value="time" @change="onTimeChange">
				<view v-if="time" class="uni-input">{{ time }}</view>
				<view v-else class="uni-input" style="color: #A9ABB0;">请选择时间</view>
			</picker>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			time: '',
			params: {hour: false,minute: false},
		};
	},
	created(){
		this.time=this.vuex_user.noticeTime
		// console.log(this.vuex_user.noticeTime,'')
	},
	methods: {
		onTimeChange(e) {
			// 确认时间
			this.time = e.detail.value;
			this.setNoticTime(1,this.time)
		},
		removeNoticeTime() {
			// 取消提醒
			this.time = ''
			this.setNoticTime(0,this.time)
		},
		setNoticTime(type,time){
			// 设置缓存中的数据
			this.time = time;
			this.vuex_user.noticeTime=this.time
			this.updateUser(this.vuex_user)
			// 接口更改密码
			return new Promise((resolve, reject) => {
				this.request
					.get('/app/mine/setNotice', {'type':type+'','time':time})
					.then(res => {
						uni.showToast({
								icon: 'none',
								title: '设置成功',
								success: () => {
									uni.navigateBack({
										delta: 1
									});
								}
					  });

						resolve()
					});
			});
		}
	}
};
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>
<style scoped lang="scss">
.nav-bar__cancel {
	font-size: 30upx;
	font-weight: 400;
	color: #ffffff;
	margin-right: 30upx;
}
.pick-time {
	height: 110upx;
	margin-top: 20upx;
	background-color: #ffffff;
	display: flex;
	align-items: center;
	padding: 0 30upx;
	font-size: 32upx;
	font-weight: 400;
	color: #363940;
	text {
		margin-right: 48upx;
	}
	picker {
		flex: 1;
	}
}
</style>
